#!/bin/bash

nginx_home=/opt/module/nginx/sbin
log_home=/opt/module/gmall_1026
app=gmall_logger-0.0.1-SNAPSHOT.jar

case $1 in

"start")
    if [ -z "`ps -ef | awk '/nginx/ && !/awk/{ print \$n} ' `" ]; then
        echo "===========启动 nginx==========="
        ssh hadoop162 "$nginx_home/nginx"
    else
        echo "hadoop162上nginx已经启动........."
    fi

    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "===========启动日志服务器==========="
        ssh $host "nohup java -jar $log_home/$app >/dev/null 2>&1 & "
    done

;;
"stop")
    if [ -z "`ps -ef | awk '/nginx/ && !/awk/{ print \$n} ' `" ]; then
        echo "hadoop162上nginx已经关闭........."
    else
        echo "===========关闭 nginx==========="
        ssh hadoop162 "$nginx_home/nginx -s stop"
    fi

    for host in hadoop162 hadoop163 hadoop164 ; do
        echo "===========启动日志服务器==========="
        ssh $host "jps | awk '/gmall/ {print\$1}' | xargs kill -9"
    done

;;

*)
   echo "你启动的姿势不对"
    echo "log.sh start 启动日志采集集群"
    echo "log.sh stop  停止日志采集集群"
;;

esac
